﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml.Controls;
using WPClient.Common;
using WPClient.View;

namespace WPClient.ViewModel
{
    class HomePageViewModel : ViewModelBase
    {
        #region Fields and RelayCommands

        IEnumerable<string> _politicGroups;

        RelayCommand _logInCommand;

        #endregion

        #region Public Interface

        public HomePageViewModel()
        {
        }

        public async void Initialize()
        {
            //var response = await new HttpClient().GetAsync("http://cpservice.azurewebsites.net/api/PoliticGroups");
            //JObject o = JObject.Parse(response.Content.ToString());

            //PoliticGroups = o[""].Select(s => (string)s).ToArray();
        }

        #endregion

        #region Properties

        public IEnumerable<string> PoliticGroups
        {
            get { return _politicGroups; }
            set
            {
                if (value == _politicGroups)
                    return;
                _politicGroups = value;
                OnPropertyChanged("PoliticGroups");
            }
        }

        #endregion

        #region Commands

        public ICommand LogInCommand
        {
            get
            {
                if (_logInCommand == null)
                {
                    _logInCommand = new RelayCommand(
                        () =>
                        {
                            //if (!Frame.Navigate(typeof(UserLoginPage)))
                            //    throw new Exception("Navigation Failed");
                        });
                }
                return _logInCommand;
            }
        }

        #endregion
    }
}
